<template>
	<view class="body-bar">
		<template v-for="item in serviceStepData" :key="item._id">

			<view class="record-bar" v-if="item.state==1||item.state==2||item.state==3||item.state==0"
				@click="toDetail(item._id)">
				<view class="record-type " v-if="item.state==0" style="color: #FA746B;">
					申请失败
				</view>
				<view class="record-type " v-else-if="item.state==1" style="color: #28D094;;">
					待审核
				</view>
				<view class="record-type " v-else-if="item.state==2" style="color: #FDDB78;;">
					审核通过
				</view>
				<view class="record-type " v-else-if="item.state==3">
					已完成
				</view>
				<view class="record-content">
					<view class="content-bar">
						<view class="head-bar">
							<text>{{item.doctorId?.name}}</text>
							<view class="tag-item" v-if="item.serviceId?.place=='机构门诊'"
								style="color: #FA746B;background-color: rgba(250, 116, 107, 0.2);">
								{{item.serviceId?.place?item.serviceId?.place:'机构门诊'}}
							</view>
							<view class="tag-item" v-else
								style="color: #FDDB78;background-color: rgba(253, 219, 120, 0.0980392156862745)">
								{{item.serviceId?.place?item.serviceId?.place:'上门服务'}}
							</view>
						</view>
						<view class="time-bar" v-if="item.time">
							{{'服务时间：'+item.time}}
						</view>
						<view class="time-bar" v-else>
							2021/2/4 10:30
						</view>
						<view class="comment" v-if="item.state==3">
							<text style="font-size: 24rpx;color: #999;">服务评价：</text>
							<uni-rate :value="item.doctorId?.rate" :size="16" :resdonly="true"
								v-if="item.doctorId?.rate" />
							<text v-if="item.doctorId?.rate"
								style="color: #FDDB78;font-size: 24rpx;margin-left: 20rpx;">{{item.doctorId?.rate+'.0'}}</text>
							<text v-if="!item.doctorId?.rate" style="font-size: 24rpx;">暂无评分</text </view>
						</view>
					</view>

					<text style="font-size: 30rpx;color: #999;font-weight: 450;">></text>

				</view>
			</view>
			<view class="record-bar" v-else style="background-color: #dbdbdb;">
				<view class="record-type " style="color: #999;">
					已取消
				</view>

				<view class="record-content">
					<view class="content-bar">
						<view class="head-bar">
							<text>{{item.doctorId?.name}}</text>
							<view class="tag-item" v-if="item.serviceId?.place=='机构门诊'"
								style="color: #FA746B;background-color: rgba(250, 116, 107, 0.2);">
								{{item.serviceId.place}}
							</view>
							<view class="tag-item" v-else
								style="color: #FDDB78;background-color: rgba(253, 219, 120, 0.0980392156862745)">
								{{item.serviceId?.place}}
							</view>
						</view>
						<view class="time-bar" v-if="item.time">
							{{'服务时间：'+item.time}}
						</view>
						<view class="time-bar" v-else>
							2021/2/4 10:30
						</view>
					</view>
					<text style="font-size: 30rpx;color: #999;font-weight: 450;">></text>
				</view>
			</view>
		</template>
	</view>
</template>
<script setup>
	import {
		ref
	} from 'vue';
	import {
		getServiceStepApi
	} from '../../../api/servicePackage';
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	import {
		useUserStore
	} from '../../../store/user';
	const serviceId = ref('')
	onLoad((options) => {
		getServiceStep(options._id)
		serviceId.value = options._id
	})
	onShow(() => {
		if (serviceId.value) {
			getServiceStep(serviceId.value)
		}
	})
	const userStore = useUserStore()
	const serviceStepData = ref([]);

	// 前往详情也
	function toDetail(data) {
		uni.navigateTo({
			url: `/serviceStep/pages/serviceDetail/serviceDetail?_id=${data}`
		})
	}

	// 获取服务进度
	function getServiceStep(data) {
		getServiceStepApi({
				residentId: userStore.userInfo?._id,
				serviceItemId: data
			})
			.then(res => {
				if (res.code == 200) {
					serviceStepData.value = res.data.rows
				}
			})
	}
</script>
<style scoped>
	.body-bar {
		min-height: 100vh;
		width: 750rpx;
		background-color: rgba(242, 242, 242, 1);

		padding-top: 20rpx;
		box-sizing: border-box;
	}

	.record-bar {
		width: 686rpx;
		height: 342rpx;
		padding: 15rpx 24rpx 0;
		margin: 0 auto;
		margin-bottom: 32rpx;
		background-color: #fff;
		box-sizing: border-box;

	}

	.record-type {
		height: 58rpx;
		font-size: 28rpx;
		color: #333;
		line-height: 58rpx;
		border-bottom: 1px solid #e6e6e6;
	}

	.record-content {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: calc(342rpx - 58rpx);

	}

	.head-bar {
		display: inline-block;
		display: flex;
		font-size: 36rpx;
		line-height: 60rpx;
		color: #333;
		margin-right: 15rpx;
		margin-bottom: 20rpx;
		line-height: 36rpx;
		align-items: center;
	}

	.tag-item {
		white-space: nowrap;
		width: 66px;
		height: 48rpx;
		font-size: 24rpx;
		display: inline-block;
		box-sizing: border-box;
		color: #3DD4A7;
		background-color: rgba(61, 212, 167, 0.2);
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: 20rpx;
		line-height: 24rpx;
		border-radius: 16rpx;
	}

	.time-bar {
		color: #999;
		font-size: 24rpx;
		margin-bottom: 20rpx;
		display: inline-block;
		line-height: 24rpx;

	}

	.content-box {
		display: inline-block;
		max-height: 228rpx;
	}

	.commont-bar {
		display: inline-block;
		display: flex;
		align-items: center;
		color: #999;
		font-size: 24rpx;
	}

	.comment {
		display: inline-block;
		display: flex;
		align-items: center;
		color: #999;
		font-size: 24rpx;
	}
</style>